//
//  MeViewController.m
//  pmmSS
//
//  Created by Mac book on 2017/9/8.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "MeViewController.h"
#import "MeHeaderView.h"
#import "MeCell.h"

#import "UserMessageController.h"
#import "All_Orader_ViewController.h"
#import "Address_Manager_Controller.h"
#import "CollectViewController.h"
@interface MeViewController ()<MeHeaderViewDelegate>


@property(nonatomic,strong)NSArray * categorys;
@property(nonatomic,strong)NSMutableArray * dataArray;

@end

@implementation MeViewController

-(NSMutableArray *)dataArray{

    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
-(NSArray *)categorys{
    if (!_categorys) {
        _categorys = @[ @{
                            @"iconImage" : @"nil",
                            @"iconTitle" : @"我的地址",
                            },

                        @{
                            @"iconImage" : @"nil",
                            @"iconTitle" : @"我的收藏",
                            },

                       @{
                           @"iconImage" : @"nil",
                           @"iconTitle" : @"联系我们",
                           },
                       @{
                           @"iconImage" : @"nil",
                           @"iconTitle" : @"意见反馈",
                           },
                       @{
                           @"iconImage" : @"nil",
                           @"iconTitle" : @"设置",
                           },

                       ];
    }
    return _categorys;
}

- (void)viewDidLoad {

    NSLog(@"我的界面");

    [super viewDidLoad];

    [self loadData];


}
-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    [self setUpNavBar];


}
-(void)setUpNavBar{


    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bgimage"] forBarMetrics:UIBarMetricsDefault];
    self.title = @"我的";
    self.titleColor = [UIColor whiteColor];
    
    
}
-(void)setUpTableView:(UITableView *)tableView{


    tableView.tableFooterView.backgroundColor = View_BackgroundColor;
    tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

    MeHeaderView * headerView = [[MeHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, autoScaleH(359))];

    headerView.delegate = self;

    headerView.backgroundColor = [UIColor whiteColor];

    tableView.tableHeaderView = headerView;

    [tableView registerClass:[MeCell class] forCellReuseIdentifier:@"MeCell"];


}
#pragma TableView delegate&dataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


    MeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeCell"];

    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    [cell reloadWithModel:self.dataArray[indexPath.row]];

    return cell;




}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return autoScaleH(50);
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {


        if (indexPath.row == 0) {

            Address_Manager_Controller * vc = [[Address_Manager_Controller alloc] init];


            [self.navigationController pushViewController:vc animated:YES];

        } else if (indexPath.row == 1){

            CollectViewController * vc = [[CollectViewController alloc] init];

            [self.navigationController pushViewController:vc animated:YES];

            
        } else if (indexPath.row == 2){

        [self showActionSheetWith:nil message:@"工作时间: 9:00-23:00" options:@[@"1234567891011"] clickCallBack:^(UIAlertAction *action,NSArray * textFields) {
                NSLog(@"%@",action.title);
            }];
            
        } else if (indexPath.row == 3){


        } else if (indexPath.row == 4){


        }

        
    }

}
-(void)loadData{

    for (int i = 0; i < self.categorys.count; i++) {

        NSDictionary * dic = [_categorys objectAtIndex:i];

        MeModel *model = [MeModel initWithDic:dic];

        [self.dataArray addObject:model];
        NSLog(@"self.dataArray == %lu",(unsigned long)self.dataArray.count);

    }

}

#pragma mark : MeHeaderViewDelegate

-(void)clickButtonTag:(NSInteger)buttonTag{

    NSLog(@"buttonTag=======%ld",buttonTag);
        switch (buttonTag) {
            case 101:
            {
                UserMessageController * vc = [[UserMessageController alloc] init];

                [self.navigationController pushViewController:vc animated:YES];

    
            }
                break;
            case 102:
            {
    
            }
                break;
            case 103:
            {
    
            }
                break;
            case 104:
            {

                All_Orader_ViewController * vc = [[All_Orader_ViewController alloc] init];

                vc.buttonTagValue = buttonTag;

                [self.navigationController pushViewController:vc animated:YES];

            }
                break;
            case 105:
            {
               All_Orader_ViewController * vc = [[All_Orader_ViewController alloc] init];

                vc.buttonTagValue = buttonTag;

                [self.navigationController pushViewController:vc animated:YES];
            }
                break;
            case 106:
            {
                All_Orader_ViewController * vc = [[All_Orader_ViewController alloc] init];

                vc.buttonTagValue = buttonTag;
                [self.navigationController pushViewController:vc animated:YES];
            }
                break;
            case 107:
            {
             All_Orader_ViewController * vc = [[All_Orader_ViewController alloc] init];

                vc.buttonTagValue = buttonTag;

                [self.navigationController pushViewController:vc animated:YES];
            }
                break;
            case 108:
            {
                All_Orader_ViewController * vc = [[All_Orader_ViewController alloc] init];

                vc.buttonTagValue = buttonTag;

                [self.navigationController pushViewController:vc animated:YES];
            }
                break;
    
            default:
                break;
        }



}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
